package com.newstore.view;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.newstore.R;
import com.newstore.classes.Barcode;
import com.newstore.classes.Order;
import com.newstore.database.BarcodeDatabase;
import com.newstore.database.OrderDatabase;

public class DisplayBarcode extends Activity
{
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.barcode);
	        
	        TextView tvBarcode = (TextView)findViewById(R.id.tvBarcode);
	        Button btImprimer = (Button)findViewById(R.id.BtImprimer);
	        
	        Barcode barcode = new Barcode();
	    	int idOrder = getIntent().getIntExtra("id", 0);
	        barcode.generateBarcodeNumber(idOrder, true);
	 //*       
	        SQLiteDatabase myDb = Authentication.accessDB.open(true);
	        BarcodeDatabase barcodeDb = new BarcodeDatabase(myDb);
	        long idBarcode = barcodeDb.insertBarcode(barcode);
	        
			OrderDatabase usDb = new OrderDatabase(myDb);
			usDb.updateBarcodeOrderFromId(idOrder, (int)idBarcode);
			usDb.updateStatusOrderFromId(idOrder, "Préparée");
			Authentication.accessDB.close();
			//*/
			barcode.generateBarcode(this, tvBarcode);
			
			btImprimer.setOnClickListener(new View.OnClickListener() {
		            public void onClick(View v) {
		            	Toast.makeText(getApplicationContext(),
								"Impression en cours", Toast.LENGTH_SHORT)
								.show();
		            	
		            	startListOrder();
		            }
            });
			
	 }
	 
	 public void startListOrder(){
		 Intent intent = new Intent(this, ListOrder.class);
			startActivity(intent);
	 }
}
